﻿using MediatR;
using S.Breeding.Api.Application.Command.BodyMeasureCommand;
using S.Breeding.Domain;
using S.Breeding.Infrastructure;

namespace S.Breeding.Api.Application.CommandHandlers.BodyMeasureCommandHandlers
{
    public class BodyMeasureBatchCommandHandlers:IRequestHandler<BodyMeasureBatchCommand,int>
    {
        private readonly IRepository<BodyMeasure> repository;
        private readonly IMediator mediator;
        public BodyMeasureBatchCommandHandlers(IRepository<BodyMeasure> repository, IMediator mediator)
        {
            this.repository = repository;
            this.mediator = mediator;
        }

        public async Task<int> Handle(BodyMeasureBatchCommand request, CancellationToken cancellationToken)
        {
            string[] ids = request.Array.ToString().Split(",");
            foreach (var item in ids)
            {
               await  repository.DeleteAsync(int.Parse(item));
            }
            return 1;
        }
    }
}
